package cn.com.shopec.erp.common.utils;

import java.beans.PropertyEditorSupport;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import org.springframework.util.StringUtils;


/**
 * Spring MVC 日期数据格式化类
 * 
 * 格式化为 yyyy-MM-dd,yyyy-MM-dd HH:mm:ss
 *
 */
public class DateEditor extends PropertyEditorSupport {
	
	public void setAsText(String text) throws IllegalArgumentException {

		if(StringUtils.hasText(text) && text.length() <= DateUtil.DEFAULT_PATTERN.length()){
			setValue(DateUtil.parseDefaultDate(text.trim()));
		}else if(StringUtils.hasText(text) && text.length() > DateUtil.DEFAULT_PATTERN.length()){
			setValue(DateUtil.parseTimesTampDate(text.trim()));
		}else{
			setValue(null);
			return;
		}
	}

	public String getAsText() {
		Date value = (Date) getValue();
		return (value != null ? DateUtil.formatTimesTampDate(value) : "");
	}
	
	public static void main(String[] args) {
		Set<Integer> result = new HashSet<Integer>();
		Set<Integer> set1 = new HashSet<Integer>(){{
			add(1);
			add(3);
			add(5);
		}};
		
		Set<Integer> set2 = new HashSet<Integer>(){{
			add(2);
			add(4);
			add(6);
		}};
		
		Set<Integer> set3 = new HashSet<Integer>(){{
			add(3);
			add(4);
			add(5);
		}};
		
		result.clear();
		result.addAll(set1);
		result.retainAll(set2);
		result.retainAll(set3);
		System.out.println("交集："+result);
		
		result.clear();
		result.addAll(set1);
		result.removeAll(set2);
		System.out.println("差集："+result);
		
		result.clear();
		result.addAll(set1);
		result.addAll(set2);
		System.out.println("并集："+result);
		
		result.clear();
		//set2.addAll(set1);
		result.addAll(set1);
		System.out.println("交集："+set1.size());
		set1.retainAll(set2);
		System.out.println("交集："+result.size());
		
	}
}